<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>06 goodslist分类</title>
    <script src="./js/vue.js"></script>
    <script src="./js/axios.min.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        #app {
            margin: 0 auto;
        }

        .table {
            margin: 20px auto;
            width: 1200px;
        }

        .table .item {
            margin-right: 40px;
            width: 200px;
            height: 300px;
            float: left;
        }

        .table .item .img {
            width: 200px;
            height: 200px;
        }

        .type {
            width: 1200px;
            margin: 20px auto;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="type">
            <p>
                分类
                全部<input type="radio" name="type" value="" v-model="type">
                服装<input type="radio" name="type" value="1" v-model="type">
                手机<input type="radio" name="type" value="2" v-model="type">
                箱包<input type="radio" name="type" value="3" v-model="type">
                美妆<input type="radio" name="type" value="4" v-model="type">
            </p>
        </div>
        <div class="table">
            <div class="item" v-for="item in list" :key="item.id">
                <img :src="item.goodsimg" alt="" class="img">
                <p>商品名称：{{item.goodsname}}</p>
                <p class="num">数量{{item.goodsnum}}</p>
                <p class="price">价格{{item.goodsprice}}</p>
            </div>
        </div>

    </div>

</body>
<script>
    new Vue({
        el: "#app",
        data: {
            list: [],
            type: "",

        },
        async created() {

            this.search();

        },
        methods: {

            async search() {

                let params = {
                    
                }
                
                if(this.type){
                    params.type = this.type;
                }
                

                let { data: list } = await axios({
                    method: "get",
                    url: "http://localhost:2345/goodslist",
                    params,
                })

                this.list = list;

            }


        },
        watch: {
            type(){
                this.search();
            },

        }
    })
</script>

</html>